document.addEventListener('DOMContentLoaded', () => {
    const cards = document.querySelectorAll('.recommendation-card');
    cards.forEach((card, index) => {
        card.style.setProperty('--index', index);
        card.addEventListener('click', () => {
            card.classList.add('animate__animated', 'animate__pulse');
        });
    });

    // 滚动触发动画
    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.style.opacity = 1;
                entry.target.style.transform = 'translateY(0)';
            }
        });
    }, { threshold: 0.1 });

    document.querySelectorAll('.recommendation-card').forEach(card => {
        observer.observe(card);
    });

    // 预算进度条动画
    const progressBars = document.querySelectorAll('.budget-progress-bar');
    progressBars.forEach(bar => {
        const targetWidth = parseFloat(bar.style.width);
        bar.style.width = '0%';
        setTimeout(() => {
            bar.style.width = targetWidth + '%';
        }, 300);
    });
});

// 添加菜单动画逻辑
const burgerMenu = document.querySelector('.burger-menu');
const navLinks = document.querySelector('.nav-links');

burgerMenu.addEventListener('click', () => {
    navLinks.classList.toggle('active');
    burgerMenu.classList.toggle('tapped');
    document.body.classList.toggle('menu-open');
});

// 添加点击外部关闭菜单
document.addEventListener('click', (e) => {
    if (!e.target.closest('.nav-links') && !e.target.closest('.burger-menu')) {
        navLinks.classList.remove('active');
        burgerMenu.classList.remove('tapped');
        document.body.classList.remove('menu-open');
    }
});

// 添加菜单项点击动画
document.querySelectorAll('.apple-menu-item').forEach(item => {
    item.addEventListener('click', () => {
        item.style.transform = 'scale(0.96)';
        setTimeout(() => item.style.transform = '', 120);
    });
});